package com.chatroomserver.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chatroomserver.entity.Notice;
import com.chatroomserver.mapper.NoticeMapper;
import com.chatroomserver.service.NoticeService;
import org.springframework.stereotype.Service;

@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Override
    public Notice getLatestNotice() {
        LambdaQueryWrapper<Notice> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Notice::getCreateTime).last("LIMIT 1");
        return getOne(wrapper);
    }

    @Override
    public boolean createNotice(String userId, String content) {
        Notice notice = new Notice();
        notice.setId(IdUtil.simpleUUID());
        notice.setUserId(userId);
        notice.setContent(content);
        return save(notice);
    }
}
